﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.IDAL;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_manager_role_popedom : AdminBasePage
{
    public IList columnlist;
    public IList syscolumnlist;

    private Hashtable map;
    protected void Page_Load(object sender, EventArgs e)
    {
        RolePopedomBll rpbll = new RolePopedomBll();
        if (!IsPostBack)
        {
            this.PopedomValidate(Layerid, MOD);
            string rname = (string)Request.QueryString["rn"];

            if (rname != null && rname != "")
            {
                OgilvyOne.BLL.RoleBll rolebll = new OgilvyOne.BLL.RoleBll();
                OgilvyOne.Model.RoleModel role = rolebll.GetModel(rname);
                this.rid.Value = role.Rid.ToString();
                this.rolename.Value = role.Rolename;
                this.rolenametext.Text = role.Rolename;

                map = rpbll.getRolePopedomList(role.Rid);
            }
            reader.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
        }

        LoginBll lb = new LoginBll();
        columnlist = rpbll.getColumnList();
        syscolumnlist = rpbll.getSysColumnList();

        
    }

    public string isPopedom(string layerid, string option)
    {
        bool isp = false;
        if (map != null)
        {
            string p = (string)map[layerid];
            isp = (option == QUERY && p != null) || (p != null && p.IndexOf(option) > -1);
        }
        if (isp == true) return " checked=checked";
        return "";
    }


    protected void btn_Click(object sender, EventArgs e)
    {
        map = new Hashtable();
        string p001 = Request.Form["id001"];
        IList popedomlist = new ArrayList();
       
        if (p001 != null && p001 != "")
        {
            Hashtable modmap = new Hashtable();
            modmap["layerid"] = "001";
            modmap["popedom"] = p001;
            map.Add("001", p001);
            popedomlist.Add(modmap);
        }

        
        bool issys = false;
        for (int i = 0; i < syscolumnlist.Count; i++)
        {
            UserColumnModel ucm = (UserColumnModel)syscolumnlist[i];
            string popedoms = Request.Form["id"+ucm.Columnid];
            if (popedoms != null && popedoms != "")
            {
                Hashtable modmap = new Hashtable();
                modmap["layerid"] = ucm.Layerid;
                modmap["popedom"] = popedoms;
                map.Add(ucm.Layerid, popedoms);
                popedomlist.Add(modmap);
                issys = true;
            }
        }
        if (issys == true)
        {
            Hashtable modmap = new Hashtable();
            modmap["layerid"] = "003";
            modmap["popedom"] = "show";
            map.Add("003", "show");
            popedomlist.Add(modmap);
        }

        bool iscon = false;
        for (int i = 0; i < columnlist.Count; i++)
        {
            UserColumnModel ucm = (UserColumnModel)columnlist[i];
            string popedoms = Request.Form["id" + ucm.Columnid];
            if (popedoms != null && popedoms != "")
            {
                Hashtable modmap = new Hashtable();
                modmap["layerid"] = ucm.Layerid;
                modmap["popedom"] = popedoms;
                map.Add(ucm.Layerid, popedoms);
                popedomlist.Add(modmap);
                iscon = true;
            }
        }
        if (iscon == true)
        {
            Hashtable modmap = new Hashtable();
            modmap["layerid"] = "002";
            modmap["popedom"] = "show";
            map.Add("002", "show");
            popedomlist.Add(modmap);
        }

        new RolePopedomBll().saveRolePopedom(int.Parse(this.rid.Value), popedomlist);

        this.message.Text = "<script>alert('保存成功!');</script>";

    }
}
